# encoding:utf-8
# !@Time:2022/3/2 16:14
# !@Author:zy
from catch import *
from saveAsYamlFile import save
from email_util import send_email
import schedule
import yaml
from jsoncompare import JsonCompare


def main():
    result = {**tomcat(),
              **ApacheShiro(),
              **xstream(),
              **ApacheVelocity(),
              **ApacheCommonsCollections(),
              **WildFly(),
              **Nginx(),
              **ApacheLog4j(),
              **FastJson(),
              }
    save(result, './cache.yml')
    with open('./cache.yml', "r", encoding="gbk") as n:
        new_da = yaml.load(n, Loader=yaml.FullLoader)
    with open('./crawlerResult.yml', "r", encoding="gbk") as o:
        old_da = yaml.load(o, Loader=yaml.FullLoader)

    diff = JsonCompare(new_da, old_da).compare(new_da, old_da)
    if diff:
        message = diff
        title = "组件有更新"
        print(diff)
        save(result, './crawlerResult.yml')
        send_email(['zhengyi@myhexin.com', 'lihaoze@myhexin.com'], title, str(message))

    else:
        title = '今日巡检无组件更新'
        message = '无'
        send_email(['zhengyi@myhexin.com', 'lihaoze@myhexin.com'], title, str(message))


if __name__ == '__main__':
    # schedule.every(1).minutes.do(main)
    # schedule.every().hour.do(main)
    # schedule.every().day.at("08:59").do(main)
    # schedule.every().monday.do(main)
    # schedule.every().wednesday.at("13:15").do(main)
    # while True:
    #     schedule.run_pending()
    #     time.sleep(1)

    main()
    print('end')
